package com.yzt.zhuju.network.biz;

import com.alibaba.fastjson.JSONObject;
import com.yzt.zhuju.network.NetLayer;
import com.yzt.zhuju.network.apiconfig.MessageUrlConstant;

import java.util.List;

import rx.Observable;
import rx.Observer;

/**
 * author : bob
 * date   : 2022/12/6
 * desc   :
 */
public class MessageModule extends BaseModule {

    /**
     * 获取红包状态
     */
    public void getRedPkgStatus(String redPackId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("redPacketId", redPackId);
        Observable observable = NetLayer.getInstance().getMessageService().getRedPkgStatus(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.GET_RED_MESSAGE_STATUS);
    }

    /**
     * 创建群聊
     */
    public void groupChatCreate(String groupName, List<String> userIds, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("groupName", groupName);
        json.put("userIds", userIds);
        Observable observable = NetLayer.getInstance().getMessageService().groupChatCreate(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_CREATE);
    }

    /**
     * 聊详情
     */
    public void groupChatInfo(String rongGroupId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        Observable observable = NetLayer.getInstance().getMessageService().groupChatInfo(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_DETAIL);
    }

    /**
     * 修改群名称
     */
    public void groupChatNameEdit(String groupName, String rongGroupId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("groupName", groupName);
        json.put("rongGroupId", rongGroupId);
        Observable observable = NetLayer.getInstance().getMessageService().groupChatNameEdit(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_EDIT_NAME);
    }

    /**
     * 拉去群用户列表
     */
    public void groupChatUserList(String rongGroupId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        json.put("current", 1);
        json.put("pageSize", 1000);
        Observable observable = NetLayer.getInstance().getMessageService().groupChatUserList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_USER_LIST);
    }

    /**
     * 拉去群用户列表
     */
    public void groupChatUserList(String rongGroupId, boolean oneself, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        json.put("current", 1);
        json.put("pageSize", 1000);
        json.put("oneself", false);
        Observable observable = NetLayer.getInstance().getMessageService().groupChatUserList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_USER_LIST);
    }

    /**
     * 屏蔽群组(消息免打扰 接口每次取反操作)
     */
    public void groupMessageMute(String rongGroupId, boolean status, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        json.put("current", status);
        Observable observable = NetLayer.getInstance().getMessageService().groupMessageMute(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_MUTE);
    }

    /**
     * 退出群聊
     */
    public void groupQuit(String rongGroupId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        Observable observable = NetLayer.getInstance().getMessageService().groupQuit(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_QUIT);
    }

    /**
     * 拉人群聊
     */
    public void groupInvite(String rongGroupId, List<String> userIds, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        json.put("userIds", userIds);
        Observable observable = NetLayer.getInstance().getMessageService().groupInvite(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_INVITE);
    }

    /**
     * 退出群聊
     */
    public void groupKick(String rongGroupId, List<String> userIds, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("rongGroupId", rongGroupId);
        json.put("userIds", userIds);
        Observable observable = NetLayer.getInstance().getMessageService().groupKick(getRequestBody(json));
        toSubscribe2Filter(observable, observer, MessageUrlConstant.POST_GROUP_KICK);
    }
}
